﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace jumping_on_blocks
{
    class Block
    {
        //Size of block model on each side.
        public const int BLOCK_SIZE = 2;

        private ManlyModel m_model;
        private Vector3 m_position, m_rotation, m_scale;
        private BoundingBox m_boundingBox;

        public BoundingBox boundingBox
        {
            get { return m_boundingBox; }
        }

        public ManlyModel Model
        {
            get { return m_model; }
        }

        public Vector3 Pos
        {
            get { return m_position; }
            set { m_position = value; }
        }

        public Vector3 Origin
        {
            get { return m_position - Vector3.One * m_scale; }
            set { m_position = value + Vector3.One * m_scale; }
        }

        public Vector3 Extragin
        {
            get { return m_position + Vector3.One * m_scale; }
            set { m_position = value - Vector3.One * m_scale; }
        }

        public Vector3 Rot
        {
            get { return m_rotation; }
            set { m_rotation = value; }
        }

        public Block(ManlyModel inputModel, Vector3 inputPosition, Vector3 inputRotation, Vector3 inputScale)
        {
            m_model = inputModel;
            m_position = inputPosition;
            m_rotation = inputRotation;
            m_scale = inputScale / BLOCK_SIZE;
            updateBounds();
        }

        public void Draw(Camera camera, string technique)
        {
            Matrix tempWorld = Matrix.CreateScale(m_scale) * Matrix.CreateRotationX(m_rotation.X) *
                Matrix.CreateRotationY(m_rotation.Y) * Matrix.CreateRotationZ(m_rotation.Z) * Matrix.CreateTranslation(m_position);
            m_model.Draw(camera, tempWorld, technique);
        }

        public void updateBounds()
        {
            Vector3[] points = new Vector3[2];
            points[0] = Origin;
            points[1] = Extragin;
            m_boundingBox = BoundingBox.CreateFromPoints(points);
        }
    }
}
